package com.robot.ad.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.robot.ad.pojo.Ad;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * ad数据访问接口
 *
 * @author wuyunbin
 */
public interface AdDao extends JpaRepository<Ad, String>, JpaSpecificationExecutor<Ad> {
    /**
     * 根据position和status查找广告列表
     *
     * @param position
     * @param status
     * @return
     */
    public List<Ad> findTop2ByPositionAndStatusAndDeletedAtIsNullOrderBySortDesc(String position, String status);

    /**
     * 根据position和status和areaId查找num个广告列表
     *
     * @param position
     * @param status
     * @param areaId
     * @param num
     * @return
     */
    @Query(value = "select * from ad.ad where ad.position=? and ad.status=? and (area_list like %?% or area_list='') and deleted_at is null order by sort desc limit ? ", nativeQuery = true)
    public List<Ad> findTop2ByPositionAndStatusAndAreaListLikeAndDeletedAtIsNullOrderBySortDesc(String position, String status, String areaId, int num);
}
